<?php

namespace App\Models\Common;
use Illuminate\Database\Eloquent\Model;
use Cache;

class CollTwoOption extends Model{
    //设置表的类型和表名
    protected $table='coll_two_options';
    protected $primaryKey='id';
    public $timestamps = false;
    protected $fillable = [
        'cid', 'name', 'pid','sign','sort'
    ];

    /**
     * $opt_id:选项编号
     * $sign:选项标识
     * @return： 选项名称
     */
    public static function getTwoOptionName($opt_id,$sign){
        $twoOptions=array();
        if (Cache::has('twoOptions')) {
            $twoOptions= Cache::get('twoOptions');
        }else {
            $twoOptions = self::where('sign',$sign)->orderBy('cid','asc')->get();
            $twoOptions =  setSort($twoOptions);
            Cache::forever('twoOptions', $twoOptions);
        }
        foreach($twoOptions as $v){
            if($v['sign'] == $sign && $v['cid'] == $opt_id){
                return $v['name'];
            }
        }
        return '';
    }
}